package org.john.http;

import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URLEncodedUtils;

import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLEncoder;
import java.util.List;

/**
 * Created by adsame on 17-6-29.
 */
public class UrlParamTest {
    public class Data {

    }
    public static class WinNoticeParams {

        public String adsameUserID = null;
        public String adxUserID = null;
        public String uniqueID = null;
        public Long solutionID = null;
        public Double price = null;
        public String extension = null;
        public String bidLog = null;
        public String recordID = null;
        public Boolean isPriceExplore = false;
        public Data data;
        public String nextUrl = null;
        @Override
        public String toString() {
            StringBuilder builder = new StringBuilder();
            builder.append("adsameUserID=");
            builder.append(adsameUserID == null ? "null" : adsameUserID);
            builder.append(";");
            builder.append("adxUserID=");
            builder.append(adxUserID == null ? "null" : adxUserID);
            builder.append(";");
            builder.append("uniqueID=");
            builder.append(uniqueID == null ? "null" : uniqueID);
            builder.append(";");
            builder.append("solutionID=");
            builder.append(solutionID == null ? "null" : solutionID);
            builder.append(";");
            builder.append("price=");
            builder.append(price == null ? "null" : price);
            builder.append(";");
            builder.append("extension=");
            builder.append(extension == null ? "null" : extension);
            builder.append(";");
            builder.append("bidLog=");
            builder.append(bidLog == null ? "null" : bidLog);
            builder.append(";");
            builder.append("recordID=");
            builder.append(recordID == null ? "null" : recordID);
            builder.append(";");
            builder.append("data=");
            builder.append(data == null ? "null" : data);
            builder.append(";nextUrl=");
            builder.append(nextUrl == null ? "null" : nextUrl);
            return builder.toString();
        }
    }
    public static void main(String args[]) {
        URI uri = null;
        try {
            uri = new URI("/?ext=c29sdXRpb25JRD0xMDAwMzQ5Mzkmd2luX2RhdGE9ZmFsc2UscXVhbnRvbmVfRzAxYXgzNGc5MjdjU1NqMkQwcQ&price=0.01&z=dsp&la=0&si=1&cg=1&c=1&ci=67&or=618&l=100034939&bg=1&b=100034939&_ext=eJyTFutgsrRgZGA2NDSTYpAoSstwd3UPjArJCcl3NS00dcwPyTNyTU9msjTHK2sKNMDIkIHJ0hjEMAIZZ8DAZGjKwQAEBQHPnIACFiBRSwZGQ1EG4cLSxLyS_LzU-Nz8pMyc1PjEggJmQwOgpAlYB-u3zGomCyNOBvbMtGRdoCSTqZEcgwxcl7uBYWKFsUm6pZF5cnBwlpGLQSHQWgOgBQbGYAOAgIvJ3IgR6CJLIGFhwcHAVpqXnZdfzmRqAFTBGPNxyeT5DABpGznK");
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
        WinNoticeParams params = new WinNoticeParams();
        List<NameValuePair> pairsList = URLEncodedUtils.parse(uri, "UTF-8");
        for (NameValuePair pair : pairsList) {
            String name = pair.getName();
            String value = pair.getValue();
            try {
                if (name.equals("adsame_uid")) {
                    params.adsameUserID = value;
                } else if (name.equals("quantone_uid")) {
                    params.adxUserID = value;
                } else if (name.equals("solutionID")) {
                    params.solutionID = Long.valueOf(value);
                } else if (name.equals("price")) {
                    params.price = Double.valueOf(value);
                } else if (name.equals("ext")) {
                    params.extension = value;
                } else if (name.equals("_ext")) {
                    params.bidLog = value;
                }
            } catch (NumberFormatException ex) {
                ex.printStackTrace();
                System.out.println("parse parameter error");
            }
        }
        System.out.println(params.toString());
        try {
            System.out.println(URLEncoder.encode("和谐健康", "UTF-8"));
            System.out.println(URLEncoder.encode("和谐健康", "uTf-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
}
